<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="/vue.js"></script>
</head>
<body>
    <div id="app">
        <p>总价格：{{countPrice}}</p>
        <p>单价：{{price}}</p>
        <p>数量：{{num}}</p>

        <button @click="num++">增加一个</button>
        <button @click="num == 0 ? num = 0 : num--">减少一个</button>
    </div>
    <script>
        var vm = new Vue ({
            el: "#app",
            data: {
                price: 20,
                num: 0,
            },
            computed: {
                countPrice() {
                    // console.log(this.price * this.num);
                    return this.price * this.num;
                }
            }
        })
    </script>
</body>
</html>